package com.neu.questionnaire_system.util;

import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {
    public static String getCurrentTimestamp() {
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        Date d = cal.getTime();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(d);
    }

    public static java.sql.Timestamp stringToSqlTimestamp(String inStr) {
        if (inStr == null) {
            return null;
        }
        java.sql.Timestamp tempTime = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date tmpDate = sdf.parse(inStr, new ParsePosition(0));
        tempTime = new java.sql.Timestamp(tmpDate.getTime());
        return tempTime;
    }
}
